# Copyright 2024 Huawei Technologies Co., Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ============================================================================
from mindspore import load_checkpoint, save_checkpoint
import copy

param_dict = load_checkpoint("/home/zhangyouwen/suite/mobile_commucation/accuracy/checkpoint_download/clip/clip_vit_l_14@336.ckpt")

keys = list(param_dict.keys())
keys_cp = copy.deepcopy(keys)
for key in keys_cp:
    if not key.startswith("visual"):
        del param_dict[key]
    else:
        param_dict["vision_encoder." + ".".join(key.split(".")[1:])] = param_dict[key]
        del param_dict[key]
print(param_dict)
save_checkpoint(param_dict, "/home/zhangyouwen/suite/mobile_commucation/accuracy/checkpoint_download/clip/only_visual_clip_vit_l_14@336_wo_prefix.ckpt")

param_dict = load_checkpoint("/home/zhangyouwen/suite/mobile_commucation/accuracy/llama.ckpt")

keys = list(param_dict.keys())
keys_cp = copy.deepcopy(keys)
for key in keys_cp:
    param_dict["llm_model." + ".".join(key.split(".")[1:])] = param_dict[key]
    del param_dict[key]
print(param_dict)
save_checkpoint(param_dict, "/home/zhangyouwen/suite/mobile_commucation/accuracy/llama_wo_prefix.ckpt")
